package com.atguigu.lease.web.admin.custom.converter;

import com.atguigu.lease.model.enums.ItemType;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;
/*@Component
public class StringToItemTypeConverter implements Converter<String, ItemType> {
    @Override
    public ItemType convert(String code) {

        for (ItemType value : ItemType.values()) {
            if (value.getCode().equals(Integer.valueOf(code))) {
                return value;
            }
        }
        throw new IllegalArgumentException("code非法");
    }
}*/
//if条件后面有标点符号离谱
@Component
public class StringToItemTypeConverter implements Converter<String, ItemType> {
    @Override
    public ItemType convert(String source) {
        ItemType[] values = ItemType.values();
        for (ItemType value : values) {
            System.out.println(source);
            System.out.println(value.getCode());
            if(value.getCode().equals(Integer.valueOf(source)))
                return value;
        }
        throw new RuntimeException("code非法");

    }
}
